package com.chris.homecare.components
{
	import com.chris.homecare.TextureAtlasManager;
	import com.chris.homecare.utils.CommonUtils;
	
	import feathers.controls.Button;
	import feathers.controls.LayoutGroup;
	import feathers.display.Scale9Image;
	import feathers.layout.VerticalLayout;
	import feathers.textures.Scale9Textures;
	
	import flash.geom.Rectangle;
	
	import starling.events.Event;
	
	[Event(name="complete",type="starling.events.Event")]
	public class InfoPopupComponent extends LayoutGroup
	{
		private var infoButton1:Button;
		private var infoButton2:Button;
		private var infoButton3:Button;
		private var backgroundImage:Scale9Image;
		private var layoutGroup:LayoutGroup;
		
		public function InfoPopupComponent()
		{
			super();
		}
		
		override protected function initialize():void
		{
			const texture:Scale9Textures = new Scale9Textures(TextureAtlasManager.getAtlas().getTexture("popupBackground"), new Rectangle(20,20,60,60));
			backgroundImage = new Scale9Image(texture);
			addChild(backgroundImage);
			
			layoutGroup = new LayoutGroup();
			var layout:VerticalLayout = new VerticalLayout();
			layout.gap = 10;
			layout.padding = 10;
			layoutGroup.layout = layout;
			
			infoButton1 = new Button();
			infoButton1.label = "Business";
			infoButton1.nameList.add("plain-btn");
			infoButton1.addEventListener(Event.TRIGGERED, onButtonClicked);
			infoButton1.height = 90*CommonUtils.scaleValue;
			layoutGroup.addChild(infoButton1);
			
			infoButton2 = new Button();
			infoButton2.label = "Services";
			infoButton2.nameList.add("plain-btn");
			infoButton2.addEventListener(Event.TRIGGERED, onButtonClicked);
			infoButton2.height = 90*CommonUtils.scaleValue;
			layoutGroup.addChild(infoButton2);
			
			infoButton3 = new Button();
			infoButton3.nameList.add("plain-btn");
			infoButton3.addEventListener(Event.TRIGGERED, onButtonClicked);
			infoButton3.height = 90*CommonUtils.scaleValue;
			infoButton3.label = "Team";
			layoutGroup.addChild(infoButton3);
			
			addChild(layoutGroup);
		}
		
		private function onButtonClicked(event:Event):void
		{
			if((event.target as Button).label == "Business")
			{
				this.dispatchEventWith(Event.COMPLETE, false, {page: "Business"});
			}
			
			else if((event.target as Button).label == "Services")
			{
				this.dispatchEventWith(Event.COMPLETE, false, {page: "Services"});
			}
			
			else if((event.target as Button).label == "Team")
			{
				this.dispatchEventWith(Event.COMPLETE, false, {page: "Team"});
			}
		}
		
		override protected function draw():void
		{
			super.draw();
			infoButton1.width = infoButton2.width = infoButton3.width = this.width;
			backgroundImage.width = infoButton2.width + 20;
			backgroundImage.height = layoutGroup.height;
		}
	}
}